<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="标识类型">
              <a-select placeholder="请选择标识类型" style="width: 100%" v-model="queryParam.flag">
                <a-select-option value="plan">
                  事前申请
                </a-select-option>
                <a-select-option value="reimb">
                  事后报销
                </a-select-option>
                <a-select-option value="other">
                  其他
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <a-form-item label="关联的动态表单">
              <a-select placeholder="请选择关联的表单" style="width: 100%" v-model="queryParam.formId">
                <a-select-option v-for="item in data" :value="item.id">
                  {{item.rname}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <a-form-item label="关联费用">
              <a-select placeholder="请选择关联费用" style="width: 100%" v-model="queryParam.formType">
                <a-select-option v-for="item in expenditureData" :value="item.id">
                  {{item.name}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>


          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <a-form-item label="其他标识">
              <a-input style="width: 100%" v-model="queryParam.formType" placeholder="请输入其他标识"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增配置</a-button>
      <a-button @click="handleAddModel" type="primary" icon="plus">新增动态报表</a-button>
      <a-button @click="updateUreport2DBSourse" type="primary">统一更新数据源</a-button>
      <dbSource ref="updateSource" @ok="modalFormOk"></dbSource>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />


          <a @click="handleModel(record)">模板</a>

          <a-divider type="vertical" />

          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>

        </span>


        <template slot="flag" slot-scope="text,record" >
          <span v-if="text == 'plan'">事前申请</span>
          <span v-if="text == 'reimb'">事后报销</span>
          <span v-if="text == 'other'">其他</span>
        </template>

        <template slot="formType" slot-scope="text,record" >
          <span>{{ record.formType_dictText?record.formType_dictText:record.formType }}</span>
        </template>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <ureport2Config-modal ref="modalForm" @ok="modalFormOk"></ureport2Config-modal>
  </a-card>
</template>

<script>
  import Ureport2ConfigModal from '@/views/ureport2/modules/Ureport2ConfigModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import Vue from 'vue'
  import { getAction } from '../../api/manage'
  import DBSource from './modules/Ureport2SetDBSourceModal'

  export default {
    name: "Ureport2ConfigList",
    mixins:[JeecgListMixin],
    components: {
      Ureport2ConfigModal,
      'dbSource':DBSource
    },
    data () {
      return {
        expenditureData:[],
        data:[],
        description: '动态表单配置管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '标识类型',
            align:"center",
            dataIndex: 'flag',
            scopedSlots: { customRender: 'flag' },
           },
		   {
            title: '动态表单',
            align:"center",
            dataIndex: 'formId_dictText'
           },
		   {
            title: '标识',
            align:"center",
            dataIndex: 'formType',
            scopedSlots: { customRender: 'formType' },
           },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/ureport2/ureport2Config/list",
          delete: "/ureport2/ureport2Config/delete",
          deleteBatch: "/ureport2/ureport2Config/deleteBatch",
          exportXlsUrl: "ureport2/ureport2Config/exportXls",
          importExcelUrl: "ureport2/ureport2Config/importExcel",
       },
    }
  },
    created(){
      this.init()
    },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      init(){
        getAction('/ureport2/ureport2/listAll').then(res=>{
          if(res.success){
            this.data = res.result
          }
        })
        getAction('/base/tpExpenditureAllocationInfo/queryAll').then(res=>{
          if(res.success){
            this.expenditureData = res.result
          }
        })
      },
      handleAddModel(){
        window.open( process.env.VUE_APP_URL+'/ureport/designer')
      },
      handleModel(record){
        let sourceName = Vue.ls.get('SOURCE_NAME')
        if(!sourceName || sourceName===''){
          sourceName = 'master'
        }
        window.open( process.env.VUE_APP_URL+'/ureport/designer?_u='+sourceName+'db:'+record.formId_dictText)
      },
      // 统一更新动态报表数据源 2021-08-18 liHao
      updateUreport2DBSourse(){
        this.$refs.updateSource.edit()
        this.$refs.updateSource.title = "批量修改数据源"
        this.$refs.updateSource.disableSubmit = false
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>